﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

public class CoverEntityInFo
{
    public Vector3 localPos;
    public Vector3 localEnler;
    public Vector3 localScale;
}

public class CoverMetaInfo
{
    //zipper infos
    public CoverEntityInFo pre3Info = new CoverEntityInFo()
    {
        localPos = new Vector3(58f, 90f, 115f), //-70
        localEnler = Vector3.zero,
        localScale = new Vector3(0.75f, 1f, 1f)
    };
    public CoverEntityInFo pre2Info = new CoverEntityInFo()
    {
        localPos = new Vector3(58f, 20f, 81f),//-70
        localEnler = new Vector3(50f, 0f, 0f),//+20
        localScale = new Vector3(0.75f, 1f, 1f)
    };
    public CoverEntityInFo preInfo = new CoverEntityInFo()
    {
        localPos = new Vector3(58f, -50f, 20f),//-100
        localEnler = new Vector3(30f, 0f, 0f),//+30
        localScale = new Vector3(0.9f, 1f, 1f)
    };
    public CoverEntityInFo selectInfo = new CoverEntityInFo()
    {
        localPos = new Vector3(58f, -150f, 115f),
        localEnler = Vector3.zero,
        localScale = Vector3.one
    };
    public CoverEntityInFo nextInfo = new CoverEntityInFo()
    {
        localPos = new Vector3(58f, -250f, 20f),//+100
        localEnler = new Vector3(-30f, 0f, 0f),//-30
        localScale = new Vector3(0.9f, 1f, 1f)
    };
    public CoverEntityInFo next2Info = new CoverEntityInFo()
    {
        localPos = new Vector3(58f, -320f, 81f),//+70
        localEnler = new Vector3(-50f, 0f, 0f),//-20
        localScale = new Vector3(0.75f, 1f, 1f)
    };
    public CoverEntityInFo next3Info = new CoverEntityInFo()
    {
        localPos = new Vector3(58f, -390f, 115f),//+70
        localEnler = Vector3.zero,
        localScale = new Vector3(0.75f, 1f, 1f)
    };
}

//record now select index

//change the select index => when update zipper view
public class mCoverFlow : MonoBehaviour 
{
    public UIPanel mParentPanel;
    
    public List<mEntitiy> childs = new List<mEntitiy>();

    public float _factor = 0;
    public float Factor
    {
        set
        {
            this._factor = (value +  300f) / 600f;
            UpdateScrollView(this._factor);
        }
    }


    void Start()
    {
        mParentPanel = NGUITools.FindInParents<UIScrollView>(gameObject).GetComponent<UIPanel>();
        mParentPanel.onClipMove += OnMove;
       
        this.Factor = mParentPanel.clipOffset.y * -1;
    }

    
    ///when drag, you can get select index by it's offset
    public void OnMove(UIPanel panel)
    {
        this.Factor = panel.clipOffset.y * -1;
    }
    public void UpdateScrollView(float factor)
    {
        for (int i = 0; i < childs.Count; i++)
        {
            childs[i].Smaple(Mathf.Clamp01(factor - 0.167f * i));
        }
    }
}
